﻿using EFFC.Frame.Net.Module.Extend.EWRA.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EFFC.Extends.LinqDLR2SQL;
using EFFC.Frame.Net.Unit.DB;
using EFFC.Frame.Net.Base.Data.Base;
using EFFC.Frame.Net.Module.Extend.EWRA.Attributes.Validation;
using EFFC.Frame.Net.Base.Common;
using EFFC.Frame.Net.Base.Data;
using EFFC.Frame.Net.Module.Business.Datas;
using ICPFrameLib.Business;
using ICPFrameLib.Attributes;
using EFFC.Frame.Net.Unit.DB.Parameters;
using System.Text;

namespace XHRPMIS.Business.v1._0
{
    public class DynamicForm : MyRestLogic
{

    [EWRARoute("get", "/d_form")]
    [EWRARouteDesc("获取动态表单列表")]
    [EWRAAddInput("type", "string", "类型，分为Normal,Meta", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.QueryString, true)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息',
data:[{
    uid:'UID',
    name:'动态表单名称',
    category:'分类',
    is_error:'是否出错',
    error_msg:'错误信息描述',
    is_warnning:'是否警告',
    warnning_msg:'警告信息',
    type:'类型，分为Normal,Meta'
}]
}")]
    object Select()
    {
        SetCacheEnable(false);
        var up = DB.NewMetaUnitParameter();

        var list = (from t in DB.LamdaTable(up, "EXTEND_DYNAMICFORM", "a")
                    where t.NotNull(QueryStringD.type, t.Type == QueryStringD.type)
                    orderby t.name, t.last_time descending, t.add_time descending
                    select new
                    {
                        uid = t.UID,
                        name = t.Name,
                        route = t.Route,
                        category = t.Category,
                        is_error = t.IsError,
                        error_msg = t.ErrorMsg,
                        is_warnning = t.IsWarnning,
                        warnning_msg = t.WarnningMsg,
                        type = t.Type
                    }).GetQueryList(up);
        foreach (dynamic item in list)
        {
            item.is_error = BoolStd.IsNotBoolThen(item.is_error);
            item.is_warnning = BoolStd.IsNotBoolThen(item.is_warnning);
            item.type = ComFunc.nvl(item.type) == "" ? "Normal" : ComFunc.nvl(item.type);
        }

        return new
        {
            code = "success",
            msg = "",
            data = list
        };
    }
    [EWRARoute("get", "/d_form/{uid}")]
    [EWRARouteDesc("获取指定的动态表单")]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息',
data:{
    uid:'UID',
    name:'动态表单名称',
    desc:'动态表单描述'，
    category:'分类',
    route:'动态表单路由',
    settings:'动态表单的相关设定，JSON格式',
    is_error:'是否出错',
    error_msg:'错误信息描述'，
    is_warnning:'是否警告',
    warnning_msg:'警告信息',
    template_uid:'模板uid',
    template_name:'模板名称',
    type:'类型，分为Normal,Meta'
}
}")]
    object Select(string uid)
    {
        SetCacheEnable(false);
        var up = DB.NewMetaUnitParameter();

        var list = (from t in DB.LamdaTable(up, "EXTEND_DYNAMICFORM", "a")
                    join t2 in DB.LamdaTable(up, "EXTEND_DYNAMIC_TEMPLATE", "b").LeftJoin() on t.Template_UID equals t2.UID
                    where t.UID == uid
                    select new
                    {
                        uid = t.UID,
                        name = t.Name,
                        desc = t.Desc,
                        category = t.Category,
                        route = t.Route,
                        settings = t.SettingsJson,
                        is_error = t.IsError,
                        error_msg = t.ErrorMsg,
                        is_warnning = t.IsWarnning,
                        warnning_msg = t.WarnningMsg,
                        template_uid = t2.UID,
                        template_name = t2.Name,
                        type = t.Type
                    }).GetQueryList(up);
        if (list.Count <= 0)
        {
            return new
            {
                code = "failed",
                msg = "指定的表单不存在"
            };
        }
        dynamic info = list.First();

        info.is_error = BoolStd.IsNotBoolThen(info.is_error);
        info.is_warnning = BoolStd.IsNotBoolThen(info.is_warnning);
        info.type = ComFunc.nvl(info.type) == "" ? "Normal" : ComFunc.nvl(info.type);

        return new
        {
            code = "success",
            msg = "",
            data = info
        };
    }
    [EWRARoute("post", "/d_form")]
    [EWRARouteDesc("新增一个动态表单")]
    [EWRAEmptyValid("name")]
    [EWRAAddInput("name", "string", "名称", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAAddInput("desc", "string", "描述", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("route", "string", "路由", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("category", "string", "分类", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("settings", "string", "设定参数，JSON格式的字符串", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("template_uid", "string", "模板uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("type", "string", "类型，分为Normal,Meta", "默认为Normal", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息',
uid:'新增成功后返回的UID'
}")]
    object Add()
    {
        var up = DB.NewMetaUnitParameter();
        var name = ComFunc.nvl(PostDataD.name);
        var desc = ComFunc.nvl(PostDataD.desc);
        var route = ComFunc.nvl(PostDataD.route);
        var settings = ComFunc.nvl(PostDataD.settings);
        var category = ComFunc.nvl(PostDataD.category);
        var template_uid = ComFunc.nvl(PostDataD.template_uid);
        var type = ComFunc.nvl(PostDataD.type);

        if (type == "") type = "Normal";

        if ((from t in DB.LamdaTable(up, "EXTEND_DYNAMICFORM", "a")
             where t.Name == name
             select t).IsExists(up))
        {
            return new
            {
                code = "failed",
                msg = "同名表单已经存在"
            };
        }
        var uid = Guid.NewGuid().ToString();
        DB.QuickInsert(up, "EXTEND_DYNAMICFORM", new
        {
            UID = uid,
            Name = name,
            Desc = desc,
            Category = category,
            Route = route,
            SettingsJson = settings,
            IsError = 0,
            IsWarnning = 0,
            Template_UID = template_uid,
            Type = type,
            add_id = TokenPayLoad.ID,
            add_ip = ClientInfo.IP,
            add_name = ComFunc.nvl(TokenPayLoad["username"]),
            add_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
            last_id = TokenPayLoad.ID,
            last_ip = ClientInfo.IP,
            last_name = ComFunc.nvl(TokenPayLoad["username"]),
            last_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
        });

        return new
        {
            code = "success",
            msg = "操作成功",
            uid
        };
    }
    [EWRARoute("patch", "/d_form/{uid}")]
    [EWRARouteDesc("修改一个动态表单")]
    [EWRAEmptyValid("name")]
    [EWRAAddInput("uid", "string", "uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("name", "string", "名称", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAAddInput("desc", "string", "描述", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("route", "string", "路由", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("category", "string", "分类", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("settings", "string", "设定参数，JSON格式的字符串", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("template_uid", "string", "模板uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("type", "string", "类型，分为Normal,Meta", "默认为Normal", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息',
uid:'成功后返回的UID'
}")]
    object Modify(string uid)
    {
        var up = DB.NewMetaUnitParameter();
        var name = ComFunc.nvl(PostDataD.name);
        var desc = ComFunc.nvl(PostDataD.desc);
        var settings = ComFunc.nvl(PostDataD.settings);
        var route = ComFunc.nvl(PostDataD.route);
        var category = ComFunc.nvl(PostDataD.category);
        var template_uid = ComFunc.nvl(PostDataD.template_uid);
        var type = ComFunc.nvl(PostDataD.type);

        if (type == "") type = "Normal";

        var s = from t in DB.LamdaTable(up, "EXTEND_DYNAMICFORM", "a")
                where t.UID == uid
                select t;


        if (!s.IsExists(up))
        {
            return new
            {
                code = "failed",
                msg = "表单不存在"
            };
        }
        if ((from t in DB.LamdaTable(up, "EXTEND_DYNAMICFORM", "a")
             where t.Name == name && t.UID != uid
             select t).IsExists(up))
        {
            return new
            {
                code = "failed",
                msg = "同名表单已经存在"
            };
        }
        DB.QuickUpdate(up, "EXTEND_DYNAMICFORM", new
        {
            Name = name,
            Desc = desc,
            Category = category,
            SettingsJson = settings,
            Route = route,
            Template_UID = template_uid,
            Type = type,
            last_id = TokenPayLoad.ID,
            last_ip = ClientInfo.IP,
            last_name = ComFunc.nvl(TokenPayLoad["username"]),
            last_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
        }, new
        {
            UID = uid
        });

        return new
        {
            code = "success",
            msg = "操作成功",
            uid
        };
    }
    [EWRARoute("delete", "/d_form/{uid}")]
    [EWRARouteDesc("删除一个动态表单")]
    [EWRAAddInput("uid", "string", "uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    object Delete(string uid)
    {
        var up = DB.NewMetaUnitParameter();
        var s = from t in DB.LamdaTable(up, "EXTEND_DYNAMICFORM", "a")
                where t.UID == uid
                select t;
        if (!s.IsExists(up))
        {
            return new
            {
                code = "failed",
                msg = "表单不存在"
            };
        }

        DB.QuickDelete(up, "EXTEND_DYNAMICFORM", new
        {
            UID = uid
        });

        return new
        {
            code = "success",
            msg = "操作成功"
        };
    }
    [EWRARoute("patch", "/d_form/{uid}/correct")]
    [EWRARouteDesc("标记一个动态表单正确")]
    [EWRAAddInput("uid", "string", "uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    object Correct(string uid)
    {
        var up = DB.NewMetaUnitParameter();
        BeginTrans();
        var msg = "";
        if (!DoCorrect(up, uid, ref msg, TokenPayLoad.ID, ComFunc.nvl(TokenPayLoad["username"]), ClientInfo.IP))
        {
            RollBack();
            return new
            {
                code = "failed",
                msg
            };
        }
        CommitTrans();

        return new
        {
            code = "success",
            msg = "操作成功"
        };
    }
    [EWRARoute("patch", "/d_form/{uid}/ignore_warn")]
    [EWRARouteDesc("忽略一个动态表单的警告")]
    [EWRAAddInput("uid", "string", "uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    object IgnoreWarn(string uid)
    {
        var up = DB.NewMetaUnitParameter();
        BeginTrans();
        var msg = "";
        if (!DoIgnorWarn(up, uid, ref msg, TokenPayLoad.ID, ComFunc.nvl(TokenPayLoad["username"]), ClientInfo.IP))
        {
            RollBack();
            return new
            {
                code = "failed",
                msg
            };
        }
        CommitTrans();

        return new
        {
            code = "success",
            msg = "操作成功"
        };
    }
    [EWRARoute("patch", "/d_form/script/export")]
    [EWRARouteDesc("导出动态表单的脚本")]
    [EWRAAddInput("ids", "string", "选中要导出的表单uid，多个用逗号分隔", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息',
filetype:'文件类型',
filename:'文件名称',
filelength:'文件长度',
file:'文件内容，采用base64加密'
}")]
    object ExportScript()
    {
        string ids = ComFunc.nvl(PostDataD.ids);
        if (ids == "") return new
        {
            code = "failed",
            msg = "请选择要导出的表单"
        };
        var metaup = DB.NewMetaUnitParameter();
        var list = (from t in DB.LamdaTable(metaup, "EXTEND_DYNAMICFORM", "a")
                    where t.UID.within(ids)
                    select t).GetQueryList(metaup);
        var templateuids = string.Join(",", list.Select(d => ComFunc.nvl(d.GetValue("Template_UID"))).Where(w => w != "").ToArray());
        var templatelist = (from t in DB.LamdaTable(metaup, "EXTEND_DYNAMIC_TEMPLATE", "a")
                            where t.UID.within(templateuids)
                            select t).GetQueryList(metaup);
        foreach (dynamic item in list)
        {
            item.IsWarnning = BoolStd.IsNotBoolThen(item.IsWarnning);
            item.IsError = BoolStd.IsNotBoolThen(item.IsError);
            item.add_time = DateTimeStd.IsDateTimeThen(item.add_time, "yyyy-MM-dd HH:mm:ss");
            item.last_time = DateTimeStd.IsDateTimeThen(item.last_time, "yyyy-MM-dd HH:mm:ss");
        }
        foreach (dynamic item in templatelist)
        {
            item.IsLock = BoolStd.IsNotBoolThen(item.IsLock);
            item.add_time = DateTimeStd.IsDateTimeThen(item.add_time, "yyyy-MM-dd HH:mm:ss");
            item.last_time = DateTimeStd.IsDateTimeThen(item.last_time, "yyyy-MM-dd HH:mm:ss");
        }

        var dobj = FrameDLRObject.CreateInstance(EFFC.Frame.Net.Base.Constants.FrameDLRFlags.SensitiveCase);
        dobj.FormList = list;
        dobj.TemplateList = templatelist;
        var sign_str = ComFunc.getMD5_String(((FrameDLRObject)dobj).ToJSONString(true));
        dobj.ValidSign = sign_str;

        return FileHelper.DoDownLoad("dynamic_form.json", Encoding.UTF8.GetBytes(((FrameDLRObject)dobj).ToJSONString(true)));
    }
    [EWRARoute("patch", "/d_form/script/import")]
    [EWRAEmptyValid("data")]
    [EWRARouteDesc("导入动态表单的脚本")]
    [EWRAAddInput("data", "json", @"导入的文件，格式如下：{
filetype:'文件类型',
filename:'文件名称',
filelength:'文件长度',
file:'文件内容，采用base64加密'
}", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    object ImportScript()
    {
        dynamic data = FrameDLRObject.IsJsonThen(PostDataD.data);
        if (data == null) return new
        {
            code = "failed",
            msg = "上传格式不正确"
        };
        var file = ComFunc.nvl(data.file);
        if (string.IsNullOrEmpty(file)) return new
        {
            code = "failed",
            msg = "上传文件无效，终止操作"
        };
        var content = ComFunc.IsBase64Then(file);
        if (content == "") return new
        {
            code = "failed",
            msg = "上传文件格式无效，终止操作"
        };
        var scripts = FrameDLRObject.IsJsonThen(content, null, EFFC.Frame.Net.Base.Constants.FrameDLRFlags.SensitiveCase);
        if (scripts == null) return new
        {
            code = "failed",
            msg = "上传文件格式无效，终止操作"
        };
        var valid_sign = ComFunc.nvl(scripts.GetValue("ValidSign"));
        if (valid_sign == null) return new
        {
            code = "failed",
            msg = "上传文件不合法，终止操作"
        };
        ((FrameDLRObject)scripts).Remove("ValidSign");
        var sign_str = ComFunc.getMD5_String(scripts.ToJSONString(true));
        if (sign_str != valid_sign) return new
        {
            code = "failed",
            msg = "上传文件校验失败，终止操作"
        };
        var formlist = (IEnumerable<object>)scripts.GetValue("FormList");
        var templatelist = (IEnumerable<object>)scripts.GetValue("TemplateList");
        BeginTrans();
        var metaup = DB.NewMetaUnitParameter();
        foreach (dynamic s in templatelist)
        {
            s.IsLock = BoolStd.ConvertTo(s.IsLock, 1, 0);
            s.add_time = ComFunc.nvl(s.add_time) == "" ? DBNull.Value : s.add_time;
            s.last_time = ComFunc.nvl(s.last_time) == "" ? DBNull.Value : s.last_time;
            DB.QuickDelete(metaup, "EXTEND_DYNAMIC_TEMPLATE", new
            {
                s.UID
            });
            DB.QuickInsert(metaup, "EXTEND_DYNAMIC_TEMPLATE", s);
        }
        foreach (dynamic s in formlist)
        {
            s.IsWarnning = BoolStd.ConvertTo(s.IsWarnning, 1, 0);
            s.IsError = BoolStd.ConvertTo(s.IsError, 1, 0);
            s.add_time = ComFunc.nvl(s.add_time) == "" ? DBNull.Value : s.add_time;
            s.last_time = ComFunc.nvl(s.last_time) == "" ? DBNull.Value : s.last_time;
            DB.QuickDelete(metaup, "EXTEND_DYNAMICFORM", new
            {
                s.UID
            });
            DB.QuickInsert(metaup, "EXTEND_DYNAMICFORM", s);
        }
        CommitTrans();
        return new
        {
            code = "success",
            msg = "操作成功"
        };
    }
    /// <summary>
    /// 标记表单有错
    /// </summary>
    /// <param name="uid">动态表单uid或关联外键资料key</param>
    /// <param name="errormsg">错误原因描述</param>
    /// <returns></returns>
    public bool DoError(UnitParameter up, string id, string errormsg, ref string msg, string login_id = "", string login_name = "", string login_ip = "")
    {
        var list = (from t in DB.LamdaTable(up, "EXTEND_DYNAMICFORM", "a")
                    where t.UID == id || t.RefKey == id
                    select t).GetQueryList(up);
        if (list.Count <= 0)
        {
            msg = "指定的表单不存在";
            return false;
        }
        foreach (dynamic info in list)
        {
            DB.QuickUpdate(up, "EXTEND_DYNAMICFORM", new
            {
                IsError = 1,
                ErrorMsg = errormsg,
                last_id = login_id,
                last_name = login_name,
                last_ip = login_ip,
                last_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            }, new
            {
                info.uid

            });
        }

        return true;
    }
    /// <summary>
    /// 标记表单正确
    /// </summary>
    /// <param name="id"></param>
    /// <param name="errormsg"></param>
    /// <param name="msg"></param>
    /// <param name="login_id"></param>
    /// <param name="login_name"></param>
    /// <param name="login_ip"></param>
    /// <returns></returns>
    public bool DoCorrect(UnitParameter up, string id, ref string msg, string login_id = "", string login_name = "", string login_ip = "")
    {
        var list = (from t in DB.LamdaTable(up, "EXTEND_DYNAMICFORM", "a")
                    where t.UID == id || t.RefKey == id
                    select t).GetQueryList(up);
        if (list.Count <= 0)
        {
            msg = "指定的表单不存在";
            return false;
        }
        foreach (dynamic info in list)
        {
            DB.QuickUpdate(up, "EXTEND_DYNAMICFORM", new
            {
                IsError = 0,
                ErrorMsg = "",
                last_id = login_id,
                last_name = login_name,
                last_ip = login_ip,
                last_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            }, new
            {
                info.uid

            });
        }

        return true;
    }
    /// <summary>
    /// 标记表单警告
    /// </summary>
    /// <param name="uid">动态表单uid或关联外键资料key</param>
    /// <param name="warnmsg">警告信息描述</param>
    /// <returns></returns>
    public bool DoWarn(UnitParameter up, string id, string warnmsg, ref string msg, string login_id = "", string login_name = "", string login_ip = "")
    {
        var list = (from t in DB.LamdaTable(up, "EXTEND_DYNAMICFORM", "a")
                    where t.UID == id || t.RefKey == id
                    select t).GetQueryList(up);
        if (list.Count <= 0)
        {
            msg = "指定的表单不存在";
            return false;
        }
        foreach (dynamic info in list)
        {
            DB.QuickUpdate(up, "EXTEND_DYNAMICFORM", new
            {
                IsWarnning = 1,
                WarnningMsg = warnmsg,
                last_id = login_id,
                last_name = login_name,
                last_ip = login_ip,
                last_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            }, new
            {
                info.uid

            });
        }

        return true;
    }
    /// <summary>
    /// 标记表单正确
    /// </summary>
    /// <param name="id"></param>
    /// <param name="errormsg"></param>
    /// <param name="msg"></param>
    /// <param name="login_id"></param>
    /// <param name="login_name"></param>
    /// <param name="login_ip"></param>
    /// <returns></returns>
    public bool DoIgnorWarn(UnitParameter up, string id, ref string msg, string login_id = "", string login_name = "", string login_ip = "")
    {
        var list = (from t in DB.LamdaTable(up, "EXTEND_DYNAMICFORM", "a")
                    where t.UID == id || t.RefKey == id
                    select t).GetQueryList(up);
        if (list.Count <= 0)
        {
            msg = "指定的表单不存在";
            return false;
        }
        foreach (dynamic info in list)
        {
            DB.QuickUpdate(up, "EXTEND_DYNAMICFORM", new
            {
                IsWarnning = 0,
                WarnningMsg = "",
                last_id = login_id,
                last_name = login_name,
                last_ip = login_ip,
                last_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            }, new
            {
                info.uid

            });
        }

        return true;
    }
    /// <summary>
    /// 表单绑定外键资料
    /// </summary>
    /// <param name="up"></param>
    /// <param name="uid"></param>
    /// <param name="refkey"></param>
    /// <param name="msg"></param>
    /// <param name="login_id"></param>
    /// <param name="login_name"></param>
    /// <param name="login_ip"></param>
    /// <returns></returns>
    public bool DoBindRefKey(UnitParameter up, string uid, string refkey, ref string msg, string login_id = "", string login_name = "", string login_ip = "")
    {
        var list = (from t in DB.LamdaTable(up, "EXTEND_DYNAMICFORM", "a")
                    where t.UID == uid
                    select t).GetQueryList(up);
        if (list.Count <= 0)
        {
            msg = "指定的表单不存在";
            return false;
        }
        dynamic info = list.First();
        DB.QuickUpdate(up, "EXTEND_DYNAMICFORM", new
        {
            RefKey = refkey,
            last_id = login_id,
            last_name = login_name,
            last_ip = login_ip,
            last_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
        }, new
        {
            info.uid

        });

        return true;
    }
}
}
